regular expressions

Hello ,

i want to use Regexp function to find all reference in object text , my reference seems so  [It_absolut no.]

 

Regexp referenceIt = regexp2 "[[It_ ]]"

 

 

is my code right ?

 

Best regards,

 

 


Control17 - Mon Jul 31 04:58:48 EDT 2017

Re: regular expressions
Mike.Scharnow - Mon Jul 31 08:55:28 EDT 2017

I cannot test at this moment, but it should be something like

Regexp isReferenceIt = regexp2 "\[[Ii][Tt][_ ]+([0-9]+)\]"
string theText = oWhatever."Object Text"
string sReferencedNumber 
if (isReferenceIt theText) {
    sReferencedNumber = theText[match 1]
}

[ is a special character that starts a character class. So, if you search for a [, you need to "escape" the character.

Re: regular expressions
Control17 - Mon Jul 31 09:30:52 EDT 2017

Mike.Scharnow - Mon Jul 31 08:55:28 EDT 2017

I cannot test at this moment, but it should be something like

Regexp isReferenceIt = regexp2 "\[[Ii][Tt][_ ]+([0-9]+)\]"
string theText = oWhatever."Object Text"
string sReferencedNumber 
if (isReferenceIt theText) {
    sReferencedNumber = theText[match 1]
}

[ is a special character that starts a character class. So, if you search for a [, you need to "escape" the character.

Thank u for your help,  but i get "badly formed token" for this line

Regexp isReferenceIt = regexp2 "\[[Ii][Tt][_ ]+([0-9]+)\]"

Frown

 

Re: regular expressions
Mike.Scharnow - Mon Jul 31 09:58:44 EDT 2017

Control17 - Mon Jul 31 09:30:52 EDT 2017

Thank u for your help,  but i get "badly formed token" for this line

Regexp isReferenceIt = regexp2 "\[[Ii][Tt][_ ]+([0-9]+)\]"

Frown

 

Perhaps you need a backslash before the blank. Sorry, still don't have an installation at hand.

A more simple version would be "\[[It_\ ([0-9]+)\]". The question is how exact your users are in typing this expression concerning capitalization and separation characters.

Re: regular expressions
thsturm - Tue Aug 01 03:12:49 EDT 2017

To insert a '\' in a string you must doubble it: "\\".

So

regexp2 "\\[[Ii][Tt][_ ]+([0-9]+)\\]"

should do it.

See the Note: in the DXL Reference Manual about Regular Expressions.

Re: regular expressions
Control17 - Wed Aug 16 03:36:15 EDT 2017

thsturm - Tue Aug 01 03:12:49 EDT 2017

To insert a '\' in a string you must doubble it: "\\".

So

regexp2 "\\[[Ii][Tt][_ ]+([0-9]+)\\]"

should do it.

See the Note: in the DXL Reference Manual about Regular Expressions.

thank you , you are right Yes